package com.haust.su.ghyy.hospital.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haust.su.ghyy.common.exception.YyghException;
import com.haust.su.ghyy.common.result.ResultCodeEnum;
import com.haust.su.ghyy.hospital.mapper.HospitalSetMapper;
import com.haust.su.ghyy.hospital.service.HospitalSetService;
import com.haust.su.ghyy.model.hosp.HospitalSet;
import com.haust.su.ghyy.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

/**
 * @author haustsusu
 * @create 2023-02-13-13:53
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {


    //根据传递过来的医院编号,查询数据库,查询签名
    @Override
    public String getSignKey(String hoscode) {

        QueryWrapper<HospitalSet> wrapper=new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        return hospitalSet.getSignKey();
    }

    //根据医院编号获取签名信息
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if(null == hospitalSet) {
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }

        //分割线-------
        System.out.println("方法到获取签名信息中了");
        //分割线-------


        //分割线------
        System.out.println("hospitalset对象的属性是"+hospitalSet.toString());
        //分割线------

        //将从hospitalset中查到的数据封装到signInfoVo对象中
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;

    }
}
